// pages/product/pro-detail.js
var wxParse = require('../../vendor/wxParser/index')
const share = require('../../utils/share.js')

const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        image: []
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        share(options)
        this.setData(options)
        this.loadData()
    },
    loadData() {
        wx.showLoading({
            title: '加载中...',
        })
        app.http.get('city/goods/get-goods-details', {
            data: {
                gid: this.data.id
            },
        }).then(res => {
            this.setData({
                image: res.data.goods_banner,
                info: res.data
            })
            // if (res.data.goods_details) {
            // wxParse.wxParse("detail", "html", res.data.goods_details.content, this)
            // }
            wxParse.parse({
                bind: 'content',
                html: res.data.goods_details.content,
                target: this,
                enablePreviewImage: false, // 禁用图片预览功能
            });
            wx.setNavigationBarTitle({
                title: res.data.goods_info.name,
            })
            wx.hideLoading()
        }).catch(err => {

        })
    },

    bindReturn() {
        wx.navigateBack()
    },
    call() {
        if (this.data.phone) {
            wx.makePhoneCall({
                phoneNumber: this.data.phone,
            })
        } else {
            wx.showToast({
                title: 'Ta还没有添加电话号码',
                icon: 'none'
            })
        }

    },
    toStation() {
        wx.switchTab({
            url: '/pages/microStation/index?id=' + getApp().staion_id,
        })
    },
    onShow() {
        let timestamp = Date.parse(new Date());
        timestamp = timestamp / 1000;
        this.setData({
            timestamp
        })
    },
    onHide() {
        if (this.data.from == 1) {
            getApp().http.post('city/tiny-station/save-customer-trail', {
                data: {
                    station_member_id: this.data.member_id ? this.data.member_id : wx.getStorageSync('mid'),
                    action_type: 3,
                    action_id: this.data.id,
                    time: this.data.timestamp
                }
            })
        }
    },
    onUnload() {
        if (this.data.from == 1) {
            getApp().http.post('city/tiny-station/save-customer-trail', {
                data: {
                    station_member_id: this.data.member_id ? this.data.member_id : wx.getStorageSync('mid'),
                    action_type: 3,
                    action_id: this.data.id,
                    time: this.data.timestamp
                }
            })
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        return {
            title: this.data.info.goods_info.name,
            path: '/pages/goods/detail?id=' + this.data.info.goods_info.id + '&memberId=' + this.data.memberId + '&pmid=' + wx.getStorageSync('mid'),
        }
    }
})